package com.soilflow.info.service.impl;

import java.io.IOException;
import java.util.List;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.soilflow.common.domain.SysComment;
import com.soilflow.common.excle.DuocaiCommentExcel;
import com.soilflow.common.excle.LandInfoExcel;
import com.soilflow.common.utils.DateUtils;
import com.soilflow.common.utils.SecurityUtils;
import com.soilflow.info.mapper.SysCommentMapper;
import com.soilflow.info.service.ISysCommentService;
import com.soilflow.system.service.IColorfulUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author party
 * @date 2023-10-09
 */
@Service
public class SysCommentServiceImpl extends ServiceImpl<SysCommentMapper, SysComment> implements ISysCommentService {
    @Autowired
    private SysCommentMapper sysCommentMapper;
    @Autowired
    private IColorfulUserService colorfulUserService;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public SysComment selectSysCommentById(Long id)
    {
        return sysCommentMapper.selectSysCommentById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param sysComment 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<SysComment> selectSysCommentList(SysComment sysComment)
    {
        return sysCommentMapper.selectSysCommentList(sysComment);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param sysComment 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertSysComment(SysComment sysComment)
    {
        sysComment.setCreateTime(DateUtils.getNowDate());
        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
        sysComment.setCreateId(userId);
        sysComment.setToCommentUserId(userId);
        String userName = colorfulUserService.getById(userId).getUserName();
        sysComment.setCreateBy(userName);
        return sysCommentMapper.insertSysComment(sysComment);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param sysComment 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateSysComment(SysComment sysComment)
    {
        sysComment.setUpdateTime(DateUtils.getNowDate());
        return sysCommentMapper.updateSysComment(sysComment);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteSysCommentByIds(Long[] ids) {
        return sysCommentMapper.deleteSysCommentByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteSysCommentById(Long id)
    {
        return sysCommentMapper.deleteSysCommentById(id);
    }

    @Override
    public void export(HttpServletResponse response) throws IOException {
       List<DuocaiCommentExcel> list = this.baseMapper.export();
        EasyExcel.write(response.getOutputStream(), DuocaiCommentExcel.class).sheet().doWrite(list);
    }
}
